
#ifndef VRP_SHADOWCASTERPASS_INCLUDED
#define VRP_SHADOWCASTERPASS_INCLUDED


#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "../ShaderLib/Shadow/Shadow.hlsl"
float4 _ShadowBias;
float3 ApplyShadowBias(float3 positionWS,float3 normalWS,float3 lightDirection)
{
    float cos = dot(normalWS,lightDirection);
    // float sin = sqrt(1 - cos * cos);
    float sin = length(cross(normalWS,lightDirection));
    float depthScale = max(0.1,sin * rcp(cos));
    float normalScale = saturate(sin * rcp(cos * cos));
    positionWS -= lightDirection * _ShadowBias.x * depthScale;
    positionWS -= normalWS * normalScale * _ShadowBias.y;
    return positionWS;
}



struct ShadowCasterAttributes
{
    float4 positionOS   : POSITION;
};

struct ShadowCasterVaryings
{
    float4 positionCS   : SV_POSITION;
};

ShadowCasterVaryings ShadowPassVertex(ShadowCasterAttributes input)
{
    ShadowCasterVaryings output;
    float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
    float4 positionCS = TransformWorldToHClip(positionWS);
    #if UNITY_REVERSED_Z
    positionCS.z = min(positionCS.z, UNITY_NEAR_CLIP_VALUE);
    #else
    positionCS.z = max(positionCS.z, UNITY_NEAR_CLIP_VALUE);
    #endif
    output.positionCS =positionCS; 
    return output;
}

half4 ShadowPassFragment(ShadowCasterVaryings input) : SV_Target
{
    return 0;
}





#endif